<template>
  <div class="app-container" id="role">
    <div class="table-operation">
      <el-button @click="c()">添加地区</el-button>
    </div>

    <el-table v-loading="list.loading" :data="list.data" v-bind="tableProp">
      <el-table-column label="地区名称" prop="name" />
      <el-table-column label="所属地区">
        <template slot-scope="{ row }">
          {{ row.provinceName }}
          <template v-if="row.cityName">- {{ row.cityName }}</template>
        </template>
      </el-table-column>
      <el-table-column label="操作" align="center">
        <template slot-scope="{ row }">
          <KiPopButton :elPopconfirmProps="{ title: '确认删除吗？' }" @click="d({ code: row.code })">删除</KiPopButton>
        </template>
      </el-table-column>
    </el-table>

    <KiFormDialog
      :show.sync="form.show"
      :title="formTitle"
      v-model="form.data"
      :submit="submitForm"
      :readonly="form.status === 'r'"
      ref="formRef"
      :loading="form.loading"
    >
      <template #el-form>
        <el-form-item label="选择需要添加的地区" prop="code" verify>
          <AllRegionSelect
            v-model="form.data.code"
            :props="{
              checkStrictly: true
            }"
            placeholder="请选择需要添加的地区"
          />
        </el-form-item>
      </template>
    </KiFormDialog>
  </div>
</template>
<script>
import pageMixin from '@/utils/pageMixin'
import useAdmateAdapter from '@/utils/useAdmateAdapter'

export default {
  mixins: [pageMixin],
  setup: () =>
    useAdmateAdapter({
      urlPrefix: 'sot-admin-api/sys/areaSelect',
      axiosConfig: {
        getList: {
          url: 'listAllSelectArea'
        },
        d: {
          url: 'deleteSelectArea'
        },
        c: {
          url: 'createSelectArea'
        }
      },
      form: {
        data: {
          code: ''
        }
      },
      list: {
        dataAt: 'data'
      }
    }),
  data () {
    return {
      permission: {
        show: false,
        data: {
          permissionTree: []
        }
      }
    }
  },
  methods: {
    editPermission (row) {
      this.permission.data = {
        ...this.permission.data,
        ...this.$lo.cloneDeep(row)
      }
      this.permission.show = true
    }
  }
}
</script>
